package ynu.edu.online_course.service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ynu.edu.online_course.entity.UserRole;
import ynu.edu.online_course.mapper.UserRoleMapper;
import ynu.edu.online_course.service.UserRoleService;

import java.util.List;

@Service
public class UserRoleServiceImpl implements UserRoleService {

    @Autowired
    private UserRoleMapper userRoleMapper;

    @Override
    public List<UserRole> getRolesByUserId(Long userId) {
        List<UserRole> roles = userRoleMapper.findRolesByUserId(userId);
        roles.forEach(role -> {
            role.getUser().getId();
            role.getRole().getId();
        });
        return roles;
    }


    @Override
    public void addUserRole(UserRole userRole) {
        userRoleMapper.insertUserRole(userRole);
    }

    @Override
    public void deleteUserRole(Long userId, Long roleId) {
        userRoleMapper.deleteUserRole(userId, roleId);
    }
}

